import { BasicColumn, FormSchema } from '/@/components/Table';
import { render } from '/@/utils/common/renderUtils';
import { DescItem } from '/@/components/Description/index';
import { useI18n } from '/@/hooks/web/useI18n';
const { t } = useI18n('');
export const isEventObject = (key) => key === "0";
export const columns: BasicColumn[] = [
  {
    title: t('事件名'),
    dataIndex: 'eventValue',
    align: 'left',
    width: 160,
  },
  {
    title: t('事件键值'),
    dataIndex: 'eventKey',
    width: 160,
  },
  {
    title: t('类型'),
    dataIndex: 'type',
    width: 100,
    customRender: ({ record }) => {
      return render.renderTag(record.parentKey !== '0' ? '事件类型' : '事件对象', 'green')
    }
  },
  {
    title: t('排序'),
    dataIndex: 'sortNo',
    width: 80,
    align: 'center',
  },
  {
    title: t('创建时间'),
    dataIndex: 'createdAt',
    width: 150,
    align: 'center',
  },
  {
    title: t('创建者'),
    dataIndex: 'createdBy',
    width: 150,
  },
];

export const searchFormSchema: FormSchema[] = [
  {
    field: 'keyword',
    label: '事件',
    component: 'Input',
    componentProps: {
      placeholder: '事件键值/名',
    },
    // colProps: { span: 12 },
  },
];



export const inputFormSchemas: FormSchema[] = [
  {
    label: '',
    field: 'id',
    component: 'Input',
    show: false,
  },
  {
    label: t('事件名'),
    required: true,
    field: 'eventValue',
    component: 'Input',
    componentProps: {
      maxlength: 300,
    },
  },
  {
    label: t('事件键值'),
    required: true,
    field: 'eventKey',
    component: 'Input',
    dynamicDisabled: ({values}) => !!values.id,
    componentProps: {
      maxlength: 300,
    },
  },
  {
    label: t('事件对象'),
    required: false,
    ifShow: ({ model, field }) => model['parentKey'] && !isEventObject(model['parentKey']),
    field: 'parentKey',
    component: 'ApiSelect',
  },
  {
    field: 'sortNo',
    label: '排序',
    component: 'InputNumber',
    defaultValue: 1
  },
  {
    label: t('备注'),
    field: 'remark',
    required: false,
    component: 'InputTextArea',
    componentProps: {
      maxlength: 500,
      autoSize: {
        minRows: 3,
        maxRows: 8
      }
    }
  },
];


export const formDetailSchema: DescItem[] = [
  {
    label: t('事件名'),
    field: 'eventValue'
  },
  {
    label: t('事件键值'),
    field: 'eventKey'
  },
  {
    label: t('创建时间'),
    field: 'createdAt'
  },
  {
    label: t('更新时间'),
    field: 'updatedAt'
  },
  {
    label: t('创建者'),
    field: 'createdBy'
  },
  {
    label: t('更新者'),
    field: 'updatedBy'
  },
  {
    label: t('备注'),
    labelMinWidth: 40,
    field: 'remark'
  },
];
